import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ArenaCrossGroupNumData } from "../arenaCrossData/ArenaCrossGroupNumData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class ArenaCrossGroupSelectCellRenderer
    
    export  class ArenaCrossGroupSelectCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.init();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            return;
        }

        /* internal  */init(): void
        {
            this.initStyle();
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            this._bg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bg);
            this._bmpNumTxt = new GImageBitmap("ArenaCrossGroupItemNumBg.png", 65, 11);
            this.addChild(this._bmpNumTxt);
            var loc1=GlobalStyle.textFormatGreen;
            loc1.font = FontUtil.EmbedNumberName;
            loc1.size = 18;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfGroupNumber = ObjCreate.createEmbedTextFiled("", 83, 15, 30, 20, this);
            this._tfGroupNumber.defaultTextFormat = loc1;
            loc1 = GlobalStyle.textFormatGreen;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfGroupPlayerNum = ObjCreate.createTextField("0/0", 66, 40, 70, 20, this, loc1);
            this._btnSignUp = ObjCreate.createGButton(Language.getString(44275), 60, 58, 80, 26, this, "ButtonSpecial");
            this._btnSignUp.visible = false;
            loc1 = GlobalStyle.textFormatRed;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfHasFull = ObjCreate.createTextField(Language.getString(44276), 66, 60, 70, 20, this, loc1);
            this._tfHasFull.visible = false;
            loc1 = GlobalStyle.textFormatGreen;
            loc1.size = 14;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfHasSignUp = ObjCreate.createTextField(Language.getString(44277), 69, 60, 70, 20, this, loc1);
            this._tfHasSignUp.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.ArenaCrossGroupSignUp, this.loadedCompl);
            return;
        }

        /* internal  */addListeners(): void
        {
            return;
        }

        /* internal  */onClickSignUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._arenaCrossGroupNumData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGroupSelectGroup, this._arenaCrossGroupNumData.groupId));
            }
            return;
        }

        /* internal  */loadedCompl(): void
        {
            this._isLoaded = true;
            this.updateView();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "arenacrossgroupnumdata") 
            {
                this._arenaCrossGroupNumData = arg1 as ArenaCrossGroupNumData;
                this.updateView();
            }
            return;
        }

        public randomSelect(arg1: Boolean=false): void
        {
            if (this._isLoaded) 
            {
                if (arg1) 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossGroupItem_overSkin);
                }
                else 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossGroupItem_upSkin);
                }
            }
            return;
        }

        /* internal  */updateView(): void
        {
            if (this._isLoaded && this._arenaCrossGroupNumData) 
            {
                if (this._arenaCrossGroupNumData.isSignUpThis) 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossGroupItem_overSkin);
                }
                else 
                {
                    this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossGroupItem_upSkin);
                }
                this._tfGroupNumber.text = this._arenaCrossGroupNumData.groupId.toString();
                this._tfGroupPlayerNum.text = this._arenaCrossGroupNumData.currentNum + "/" + this._arenaCrossGroupNumData.maxNum;
                if (this._arenaCrossGroupNumData.isSignUpThis) 
                {
                    this._tfHasSignUp.visible = true;
                    this._tfHasFull.visible = false;
                }
                else if (this._arenaCrossGroupNumData.isHaveSignUp) 
                {
                    this._tfHasSignUp.visible = false;
                    this._tfHasFull.visible = this._arenaCrossGroupNumData.currentNum == this._arenaCrossGroupNumData.maxNum;
                }
                else 
                {
                    this._tfHasSignUp.visible = false;
                    this._tfHasFull.visible = this._arenaCrossGroupNumData.currentNum == this._arenaCrossGroupNumData.maxNum;
                }
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* var */_isLoaded: Boolean=false;

        /* internal */ /* var */_arenaCrossGroupNumData: ArenaCrossGroupNumData;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpNumTxt: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfGroupNumber: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfGroupPlayerNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnSignUp: GButton;

        /* internal */ /* var */_tfHasFull: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfHasSignUp: Object /* flash.text.TextField */;
    }
